package com.xing.serviceedu.controller;


import com.xing.commonutils.R;
import com.xing.commonutils.user.UcenterMemberOrder;
import com.xing.serviceedu.client.UcenterClient;
import com.xing.serviceedu.entity.EduChapter;
import com.xing.serviceedu.service.EduChapterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author xingfuao
 * @since 2022-01-09
 */
@RestController
@RequestMapping("/serviceedu/edu-chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    @Autowired
    private UcenterClient ucenterClient;

    @GetMapping("getUserInfoOrder/{id}")
    @ApiOperation("测试远程调用---")
    public R get(@PathVariable String id) {
        UcenterMemberOrder userInfoOrder = null;
        try {
            userInfoOrder = ucenterClient.getUserInfoOrder(id);
        } catch (Exception e) {
            System.out.println("异常：==============");
            e.printStackTrace();
        }
        return R.ok().data("userInfoOrder", userInfoOrder);
    }

    //课程大纲列表，根据课程id进行查询
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId) {
//        chapterService.
        return null;
    }

    //添加章节
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter) {
        chapterService.save(eduChapter);
        return R.ok();
    }

    //修改章节
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter) {
        chapterService.updateById(eduChapter);
        return R.ok();
    }

    //删除章节的方法
    @DeleteMapping("{chapterId}")
    public R deleteChapter(@PathVariable String chapterId) {
        boolean flag = chapterService.deleteChapter(chapterId);
        return flag == true ? R.ok() : R.error();
//
//      if(flag){
//          return R.ok();
//      }else {
//          return R.error();
//      }
    }

}

